// pages/notice/list.js
const config = require('../../config.js');
const request = require('../../utils/request.js');
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');

var noticeItems;
var startX;
var startY;
var endX;
var endY;
var key;

Page({
  data:{
      scrollHeight: 0, //scroll-view高度
      loadingMore: false //是否正在加载更多
  },
  onLoad:function(options){
    var that = this
    // 页面初始化 options为页面跳转所带来的参数
    wx.request({
            url: 'http://localhost:8080/api/notice/getAll',
            method: 'GET',
            data: {},
            header: {
                'Accept': 'application/json'
            },
            success: function(res) {
                that.setData({
                    noticeItems: res.data
                });
            }
        })
  },
  onReady:function(){
    // 页面渲染完成
    console.info("formatTimeFromTimestamp:"+util.formatTimeFromTimestamp(1482907810000));
  },
  drawerStart:function(e){
    var touch=e.touches[0];
    startX=touch.clientX;
    startY=touch.clientY;
    key=true;
    //
    console.info("drawerStart");
  },
  //拖动事件
  drawerMove:function(e){
    var self=this;
    var dataId=e.currentTarget.id;
    
    if(key)
    {
      var touch=e.touches[0];
      endY=touch.clientY;
      endX=touch.clientX;
      var XNum=(endX-startX)<0?startX-endX:endX-startX;
      var YNum=(endY-startY)<0?startY-endY:endY-startY;
      console.info(XNum+"____"+YNum);
      if(XNum>=YNum)
      {
        if((endX-startX)<=-5)
        {
          console.log("左滑")
        }
      }
      else
      {
        console.log("右滑")
      }
    }

    key=false;
  },
  onShow:function(){
    wx.getSystemInfo({
      success: (res) => {
        //console.log(res)
        this.setData({
          scrollHeight: res.windowHeight - (100 * res.windowWidth / 750) //80为顶部搜索框区域高度 rpx转px 屏幕宽度/750
        });
      }
    })
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
    //下拉请求数据
  scrollLowerEvent: function (e) {
    if (this.data.loadingMore)
      return;
    //requestData.call(this);
  },
  onPullDownRefresh: function() {
    // Do something when pull down.
     console.log('刷新');
 },
  onReachBottom: function() {
    // Do something when page reach bottom.
     console.log('circle 下一页');
 },
  text_plus_click:function(){
    console.info("text_plus_click");
    wx.navigateTo({
      url: 'new' 
    })
  }
})